package intnetaddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

/*获取https://www.baidu.com的所有的IP地址
使用InetAddress类的getAllByName(String host) 对某个有多个IP地址的主机可用于得到一个IP地址数组。
*/
public class Test {
    public static void main(String[] args) {
        try {
            InetAddress[] inetAddresses = InetAddress.getAllByName("www.baidu.com");
            for (int i = 0; i < inetAddresses.length; i++) {
                System.out.println("地址是：" + inetAddresses[i].getHostAddress() + "主机名：" + inetAddresses[i].getHostName());
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
